const CateDetail = require("../../utils/cateDetail");
Page({
  data: {
    detail:[]
  },
  onLoad:async function (options) {
    var {id} = options;
    var res = await CateDetail.getManDetail(id);
    console.log(res.data.res)
    var arr = res.data.res;
    var detail = [];
    arr.forEach(item => {
      var { _id, price, name, Count, isLike, pic, title, comment_num } = item;
      detail.push({
        _id,
        pic,
        name: name.slice(3, 18),
        Count,
        isLike,
        price,
        title,
        comment_num
      })
      this.setData({
        detail
      })
    })
  },
  onClickButton(event) {
    console.log(event.currentTarget.dataset);
    var { aid } = event.currentTarget.dataset;
    var detail = this.data.detail;
    detail.forEach(item => {
      if (item.id = aid) {
        item.isLike = !item.isLike;
        if (item.isLike == true) {
          var _id = item._id;
          // console.log(_id)
          var isLike = true;
          wx.request({
            url: `http://127.0.0.1:7001/likeman`,
            data: {
              id:_id,
              isLike
            },
            header: {
              'content-type': "application/x-www-form-urlencoded"
            },
            method: 'POST',
            success: function (res) {
              // console.log(res);
            },
          });
        }
      }
    })
  },
  onClickIcon(){
    console.log(1)
    wx.switchTab({
      url: '/pages/cart/index',
    })
  }
})